
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def main():
    # 指定服务器脚本路径
    server_script_path = "server.py"
    command = "python"
    args = [server_script_path]
    server_params = StdioServerParameters(command=command, args=args)
    
    async with stdio_client(server_params) as (stdio, write):
        async with ClientSession(stdio, write) as session:
            await session.initialize()
            tools = await session.list_tools()
            print("Available tools:", [tool.name for tool in tools.tools])
            
            # 调用工具示例
            result = await session.call_tool(tools.tools[0].name, {"city": "Beijing"})
            print("Tool result:")
            if isinstance(result.content, list):
                for item in result.content:
                    print(item.text)
            else:
                print(result.content)

asyncio.run(main())
